Add @conditions, smithy-model-jmespath, NodeValidationPlugin SPI#2935
Add @conditions, smithy-model-jmespath, NodeValidationPlugin SPI#2935kstich merged 18 commits intosmithy-lang:mainfrom
Conversation
|
This pull request does not contain a staged changelog entry. To create one, use the Make sure that the description is appropriate for a changelog entry and that the proper feature type is used. See |
.changes/next-release/feature-077b7f1cd574ee78042363f8d8c3afb20d56f081.json
Outdated
Show resolved
Hide resolved
smithy-contract-traits/src/main/resources/META-INF/smithy/contracts.smithy
Outdated
Show resolved
Hide resolved
smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeTypeFilter.java
Outdated
Show resolved
Hide resolved
smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeTypeMap.java
Outdated
Show resolved
Hide resolved
smithy-contracts/src/main/java/software/amazon/smithy/contracts/ConditionsTraitValidator.java
Outdated
Show resolved
Hide resolved
smithy-contracts/src/main/java/software/amazon/smithy/contracts/ConditionsTraitValidator.java
Outdated
Show resolved
Hide resolved
...mespath/src/main/java/software/amazon/smithy/model/jmespath/node/ModelJmespathUtilities.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Kevin Stich <kevin@kstich.com>
smithy-contract-traits/src/main/resources/META-INF/smithy/contracts.smithy
Show resolved
Hide resolved
smithy-contract-traits/src/main/java/software/amazon/smithy/contracts/Condition.java
Outdated
Show resolved
Hide resolved
smithy-contract-traits/src/main/java/software/amazon/smithy/contracts/Condition.java
Show resolved
Hide resolved
| private List< | ||
| ValidationEvent> validateCondition(Model model, Shape shape, String conditionName, Condition condition) { |
There was a problem hiding this comment.
Did the code formatter really do this?
There was a problem hiding this comment.
It did! I put the parameters on separate lines and that avoided it.
…ntracts/Condition.java Co-authored-by: Kevin Stich <kevin@kstich.com>
…ntracts/Condition.java Co-authored-by: Kevin Stich <kevin@kstich.com>
…hy into smithy-contracts-squashed
| import software.amazon.smithy.model.traits.Trait; | ||
|
|
||
| abstract class MemberAndShapeTraitPlugin<S extends Shape, N extends Node, T extends Trait> | ||
| public abstract class MemberAndShapeTraitPlugin<N extends Node, T extends Trait> |
There was a problem hiding this comment.
Does this need to be public for this PR?
There was a problem hiding this comment.
It's beneficial because ConditionsTraitPlugin extends it, and doesn't live in smithy-model. I'd expect most plugins to be based on some trait so most will also want to extend this.
There was a problem hiding this comment.
Oh but it needs Javadoc in that case, so I added that.
| * @return A {@link BiPredicate} that returns true if this plugin | ||
| * has an effect on Node values of the given shape. | ||
| */ | ||
| default BiPredicate<Model, Shape> shapeMatcher() { |
There was a problem hiding this comment.
You made a ShapeTypeFilter plugin. Why not replace this method with ShapeTypeFilter getFilter()?
There was a problem hiding this comment.
I was intending to leave the door open to optimize further in the future, indexing by individual shape rather than just shape type. With this signature plugins can filter more precisely if they want.
I could make the return type ShapeTypeFilter for now, since I could replace that with a supertype later without breaking folks. But I wouldn't want to make the name more specific since I can't change that later.
There was a problem hiding this comment.
Or rather if I make it getFilter() now, I might end having to add a default BiPredicate<Model, Shape> shapeMatcher() method later.
There was a problem hiding this comment.
Discussed offline and the opportunity cost is just not that high realistically, so I made the change. :)
Background
@conditions, the first "contract trait", which specifies JMESPath expressions that must evaluate totrue.smithy-model-jmespath, to contain aJmespathRuntime<T>adaptor forNodevalues.NodeValidatorPluginso that packages outside ofsmithy-modelcan provide additional node validation.NodeValidationVisitorto indexNodeValidatorPlugins byShapeType, to improve on the current approach that invokes all 10 existing plugins for every node regardless of type.ModelRuntimeTypeGeneratorand tests intosmithy-model-jmespath, to avoid having to define a third copy.Testing
NodeValidationVisitortests for the optimization.smithy-model-jmespathandsmithy-contractsBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.